//
// Created by 11510 on 2024/6/18.
//
#include <iostream>

using namespace std;

class Base {
public:
    Base(long x) : _base(x) {}

    virtual void display() const {
        cout << "Base::display()" << endl;
    }

    /* 未被override不满足动态多态条件 */
    virtual void show() const {
        cout << "Base::show()" << endl;
    }

private:
    long _base;
};

class Derived: public Base {
public:
    Derived(long base, long derived):Base(base), _derived(derived) {}

    /**
     * override告诉编译器对虚函数进行覆盖，要求函数形式完全一致
     */
    void display() const override{
        cout << "Derived::display()" << endl;
    }

    virtual void fun2() const {
        cout << "Derived::fun2()" << endl;
    }

private:
    long _derived;
};

void print(Base *pbase) {
    pbase->display();
}

void test0() {
    cout << sizeof(Base) << endl;
    cout << sizeof(Derived) << endl;

    Base* base = new Derived(4, 2);
    base->display();

    Derived d(3, 8);
    d.display();/* 这是隐藏不是多态 */

    delete base;
}

int main() {
    test0();
    return 0;
}